package com.mopon.springbootmvc;

import java.io.File;

import org.apache.catalina.valves.AccessLogValve;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.stereotype.Component;

@Component
public class MyEmbeddedServletContainerCustomizer implements EmbeddedServletContainerCustomizer {

	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
		System.out.println(container.getClass());
		TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory)container;
		factory.setPort(10003);
		// 配置tomcat生成临时文件的路径
		factory.setBaseDirectory(new File("e:/tmp/tomcat"));
		
		factory.addContextValves(getAccessLogValue());
	}

	private AccessLogValve getAccessLogValue() {
		AccessLogValve log = new AccessLogValve();
		log.setDirectory("e:/tmp/logs");
		log.setEnabled(true);
		log.setPattern("common");
		log.setPrefix("springboot-access-log");
		log.setSuffix(".txt");
		return log;
	}
}
